package com.chuangtie.tlcms.saturn.application.service.impl;

import com.chuangtie.secondary.lining.common.util.copy.BeanCopyUtil;
import com.chuangtie.tlcms.saturn.application.request.PropertyCommand;
import com.chuangtie.tlcms.saturn.application.request.PropertyQueryCommand;
import com.chuangtie.tlcms.saturn.application.response.PropertyInfoDTO;
import com.chuangtie.tlcms.saturn.application.service.PropertyService;
import com.chuangtie.tlcms.saturn.domain.aggregate.Property;
import com.chuangtie.tlcms.saturn.domain.aggregate.PropertyInfo;
import com.chuangtie.tlcms.saturn.domain.aggregate.PropertyQuery;
import com.chuangtie.tlcms.saturn.domain.repository.PropertyRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;

/**
 * @Author: 廖智威
 * @CreateTime: 2024-07-09
 */
@Service
@AllArgsConstructor
public class PropertyServiceImpl implements PropertyService {

    private final PropertyRepository propertyRepository;

    /**
     * 获取工程信息列表
     * @return
     */
    @Override
    public List<PropertyInfoDTO> propertyInfoList(PropertyQueryCommand queryCommand) {
        PropertyQuery propertyQuery = BeanCopyUtil.copy(queryCommand, PropertyQuery.class);
        List<PropertyInfo> propertyInfoList = propertyRepository.propertyInfoList(propertyQuery);
        if (!CollectionUtils.isEmpty(propertyInfoList)) {
            return BeanCopyUtil.copyListToList(propertyInfoList, PropertyInfoDTO.class);
        }

        return Collections.emptyList();
    }

    /**
     * 创建工程
     * @param requestParam
     * @return
     */
    @Override
    public Boolean createProperty(PropertyCommand requestParam) {
        Property property = BeanCopyUtil.copy(requestParam, Property.class);
        return propertyRepository.createProperty(property);
    }
}
